{% extends 'TopxiaWebBundle:CourseManage:layout.html.twig' %}

{% block title %}{% if question.id %}{{'编辑题目'|trans}}{% else %}{{'添加题目'|trans}}{% endif %} - {{ parent() }}{% endblock %}

{% set side_nav = 'question' %}
{% set script_controller = 'quiz-question/create' %}

{% block main %}

{% set parentQuestion = parentQuestion|default(null) %}

<div class="panel panel-default panel-col">
  <div class="panel-heading clearfix">
    {{'题目管理'|trans}}
  </div>
  <div class="panel-body">

    <ol class="breadcrumb">
      <li><a href="{{ path('course_manage_question',{courseId:course.id}) }}">{{'题目管理'|trans}}</a></li>
      {% if parentQuestion %}
        <li><a href="{{ path('course_manage_question',{courseId:course.id, parentId: parentQuestion.id}) }}">{{ dict_text('questionType', parentQuestion.type) }}</a></li>
      {% endif %}
      <li class="active">{% if question.id %}{{'编辑题目'|trans}}{% else %}{{'添加题目'|trans}}{% endif %}</li>
    </ol>

    <div id="question-creator-widget">
      <form id="question-create-form" data-role="question-form" class="form-horizontal quiz-question" method="post"
          action="{% if question.id %}{{ path('course_manage_question_update',{courseId:course.id, id:question.id, goto:app.request.get('goto')}) }}{% else %}{{ path('course_manage_question_create',{courseId:course.id, type:question.type, parentId:parentQuestion.id|default(0), goto:app.request.get('goto')}) }}{% endif %}"
          >
        {{ web_macro.flash_messages() }}

        {% if not parentQuestion %}
        <div class="form-group">
          <div class="col-md-2 control-label"><label>{{'从属'|trans}}</label></div>
          <div class="col-md-8 controls">
            <select class="form-control width-input width-input-large" name="target" data-role="target">
              {{ select_options(targetsChoices, question.target|default(null)) }}
            </select>
            <div class="help-block">{{'可以针对本课程或者某个课时出题'|trans}}</div>
          </div>
        </div>
        {% endif %}

        <div class="form-group">
          <div class="col-md-2 control-label"><label>{{'难度'|trans}}</label></div>
          <div class="col-md-8 controls radios">
            {{ radios('difficulty', {'simple':'简单'|trans, 'normal':'一般'|trans, 'difficulty':'困难'|trans}, question.difficulty | default('normal')) }}
          </div>
        </div>

        <div class="form-group">
          <div class="col-md-2 control-label"><label for="question-stem-field">{{ question_stem_label|default('题干'|trans) }}</label></div>
          <div class="col-md-8 controls">
            <textarea class="form-control" id="question-stem-field" data-image-upload-url="{{ path('editor_upload', {token:upload_token('course')}) }}"  data-image-download-url="{{ path('editor_download', {token:upload_token('course')}) }}" name="stem" style="height:180px;">{{question.stem | default('')}}</textarea>
            {% set question_stem_help = question_stem_help|default('') %}
            {% if question_stem_help %}<div class="help-block">{{ question_stem_help|raw }}</div>{% endif %}
          </div>
        </div>
        {{ render(controller('TopxiaWebBundle:Attachment:formFields',{targetType: 'question.stem', useType: true, targetId: question.id|default(0)},{ useType:true,})) }}


        {% block question_extra_fields %}{% endblock %}

        <div class="form-group">
          <div class="col-md-8 col-md-offset-2 controls ">
              <a href="javascript:;" data-toggle="collapse" data-role="advanced-collapse" data-target="#advanced-collapse" class="text-success collapsed">&raquo; {{'显示/隐藏 高级选项'|trans}} ...</a>
          </div>
        </div>

        <div id="advanced-collapse" class="advanced-collapse collapse">
          <div class="form-group">
            <div class="col-md-2 control-label"><label for="question-analysis-field">{{'解析'|trans}}</label></div>
            <div class="col-md-8 controls">
                <textarea class="form-control" id="question-analysis-field" data-image-upload-url="{{ path('editor_upload', {token:upload_token('course')}) }}" name="analysis" data-image-download-url="{{ path('editor_download', {token:upload_token('course')}) }}">{{ question.analysis|default('') }}</textarea>
            </div>
          </div>
           {{ render(controller('TopxiaWebBundle:Attachment:formFields',{targetType: 'question.analysis', targetId: question.id|default(0)},{ useType:true,})) }}

          <div class="form-group">
            <div class="col-md-2 control-label"><label for="question-score-field">{{'分值'|trans}}</label></div>
            <div class="col-md-4 controls">
              <input class="form-control" value="{{question.score|default(2)}}" type="text" id="question-score-field" name="score" />
            </div>
          </div>
        </div>

        <div class="form-group">
          <div class="col-md-8 col-md-offset-2 controls">
            {% block question_buttons %}
              {% if not question.id %}
                <button type="submit" data-role="submit" class="btn btn-primary submit-btn" data-submission="continue">{{'保存并继续添加'|trans}}</button>
              {% endif %}
              <button type="submit" data-role="submit" class="btn btn-primary submit-btn" data-submission="submit">{{'保存'|trans}}</button>
            {% endblock %}
            <a href="{{ path('course_manage_question', {courseId:course.id, parentId:parentQuestion.id|default(0)}) }}" class="btn btn-link">{{'返回'|trans}}</a>
          </div>
        </div>

        <input type="hidden" name="submission">
        <input type="hidden" name="type" value="{{ question.type }}">
        <input type="hidden" name="parentId" value="{{ parentQuestion.id|default(0) }}">
        <input type="hidden" name="_csrf_token" value="{{ csrf_token('site') }}">

      </form>

    </div>

  </div>
</div>


{% endblock %}
